#ifndef OMG_DDS_TOPIC_ENTITY_HPP_
#define OMG_DDS_TOPIC_ENTITY_HPP_

/* Copyright (c) 2009-2010, Real-Time Innovations, Inc.
 * Copyright (c) 2010, Object Management Group, Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * - Neither the names of the above copyright holders nor the names of their
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL A COPYRIGHT HOLDER OR CONTRIBUTOR BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */


/**
 * Topic is the most basic description of the data to be published and
 * subscribed.
 *
 * A Topic is identified by its name, which must be unique in the whole Domain.
 * In addition (by virtue of extending TopicDescription) it fully specifies the
 * type of the data that can be communicated when publishing or subscribing to
 * the Topic.
 * Topic is the only TopicDescription that can be used for publications and
 * therefore associated to a DataWriter.
 */
template <typename DELEGATE>
class tdds::topic::TopicBase :
    public dds::core::Entity,
    public virtual dds::topic::TopicDescriptionBase
{
    OMG_DDS_REFERENCE_TYPE(TopicBase)
    
public:
    /**
     * This method allows the application to retrieve the INCONSISTENT_TOPIC
     * status of the Topic.
     * Each DomainEntity has a set of relevant communication statuses.
     * A change of status causes the corresponding Listener to be invoked
     * and can also be monitored by means of the associated StatusCondition.
     * The complete list of communication status, their values, and the
     * DomainEntities they apply to is provided in Section 7.1.4.1,
     * “Communication Status,” on page 120.
     */
    const dds::topic::InconsistentTopicStatus get_inconsistent_topic_status();
    
    // --- TopicDescription methods: --- //
public:
    /**
     * Get the name used to create the TopicDescription.
     */
    virtual const std::string get_name() const;

    /**
     * The Type_name used to create the TopicDescription.
     */
    virtual const std::string get_type_name() const;

    /**
     * This operation returns the DomainParticipant to which the
     * TopicDescription belongs.
     */
    virtual dds::domain::DomainParticipant get_parent() const;
    
    // --- Entity methods: --- //
public:
    /**
     * This method closes the TopicDescription and releases all resources
     * associated with DDS, such as threads, sockets, buffers, etc. Any
     * attempt to invoke methods on a closed object will raise an
     * AlreadyClosedError.
     */
    virtual void close();
    
    using dds::core::Entity::set_qos;
    void set_qos(const dds::topic::TopicQos& qos);
    const dds::topic::TopicQos get_qos() const;
    
    // --- State: --- //
protected:
    friend class OMG_DDS_TOPIC_DELEGATE;
    DELEGATE impl_;
};


/**
 * Topic is the most basic description of the data to be published and
 * subscribed.
 *
 * A Topic is identified by its name, which must be unique in the whole Domain.
 * In addition (by virtue of extending TopicDescription) it fully specifies the
 * type of the data that can be communicated when publishing or subscribing to
 * the Topic.
 * Topic is the only TopicDescription that can be used for publications and
 * therefore associated to a DataWriter.
 */
template <typename T>
class dds::topic::Topic :
    public TopicBase,
    public TopicDescription<T>
{
    OMG_DDS_REFERENCE_TYPE(Topic)
    
public:
    typedef dds::core::StatusCondition<Topic> StatusConditionType;
    
    // --- Entity methods: --- //
public:
    StatusConditionType get_statuscondition();
    
    void set_listener(TopicListener<T>* l,
                      const dds::core::StatusMask& mask = dds::core::StatusMask::all());
    
    TopicListener<T>* get_listener() const;
};


#endif // !defined(OMG_DDS_TOPIC_ENTITY_HPP_)
